//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import { scrollMixin } from "utils/mixin";
export default {
  name:'',
  //import引入的组件需要注入到对象中才能使用
  components: {},
  mixins: [scrollMixin], //加载更多
  data() {
  return {
    active:0,
    page: 1,
    isLoadMore: true,
    total_page: 0,
    tabList:[
      {
        name:'支出',
        status:0,
        api:'plugin.love-poundage-dividend.frontend.love-account-detail.get-list'
      },
      {
        name:'收入',
        status:1,
        api:'plugin.love-poundage-dividend.frontend.love-account-detail.get-income-list'
      },
      {
        name:'转换',
        status:2,
        api:'plugin.love-poundage-dividend.frontend.love-account-detail.get-exchange-list'
      }
    ],
    recordList: [],
    usableLove:''
  };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    tabLove(event) {
      this.page = 1;
      this.recordList = [];
      this.getRecordList();
    },
    getRecordList() {
      let query = {
        page: this.page,
        // status: this.status,
        basic_info:1
      };
      $http.post(this.tabList[this.active].api, query, "加载中..").then(response => {
        if (response.result == 1) {
          let res = response.data;
          let basic_info = response.basic_info
          let recordList = res.data.data;
          this.isLoadMore = true;
          this.total_page = res.data.last_page;
          if (!this.total_page) {
            this.page = 0;
          }
          this.fun.setWXTitle(`${basic_info.love}帐目明细`);
          this.loveName = basic_info.love;
          if(res.usable_love_name) {
            this.usableLove= res.usable_love_name;
          }
          this.recordList = recordList;
        } else {
          this.page = this.page - 1;
          this.isLoadMore = false;
          this.$dialog.alert({
            message: response.msg
          });
        }
      });
    },
    //获取更多数据
    getMoreData() {
      this.isLoadMore = false; // 防止多次请求分页数据
      if (this.page >= this.total_page) {
        return;
      } else {
        this.page = this.page + 1;
        let query = {
          page: this.page,
          // status: this.status
        };
        $http.post(this.tabList[this.active].api, query, "加载中").then(
          res => {
            this.isLoadMore = true;
            if (res.result === 1) {
              let data = res.data;
              let recordList = data.data?.data;
              this.recordList = [...this.recordList, ...recordList]; //数组拼接
            } else {
              this.page = this.page - 1;
              this.isLoadMore = false;
            }
          },
          function(response) {
            console.log("response", response);
            // error callback
          }
        );
      }
    }
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
  
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
  
  },
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {
    this.page = 1;
    this.getRecordList();
  }, //如果页面有keep-alive缓存功能，这个函数会触发
}